package com.kfm.jdbc.day0403;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Demo02 {

    public static void main(String[] args) {
        String json = "{\"id\":1,\"name\":\"张三\",\"en\":\"zhangsan\",\"age\":24}";
//        System.out.println(json);

        ObjectMapper mapper = new ObjectMapper();

        try {
            Student student = mapper.readValue(json, Student.class);
            System.out.println(student);

            String s = mapper.writeValueAsString(student);
            System.out.println(s);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}


class Student{

    private Integer id;

    private String name;

    private String en;

    private Integer age;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEn() {
        return en;
    }

    public void setEn(String en) {
        this.en = en;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return super.toString() + "{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", en='" + en + '\'' +
                ", age=" + age +
                '}';
    }
}
